package com.tedu.egmvc.controller;

import com.tedu.egmvc.mapper.AddressMapper;
import com.tedu.egmvc.pojo.dto.AdderssDTO;
import com.tedu.egmvc.pojo.entity.Address;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.xml.bind.SchemaOutputResolver;
import java.util.List;

//@Controller
@RestController
public class AddressController {
    @Autowired
    private AddressMapper addressMapper;
    @RequestMapping("/address/insert")
    //@ResponseBody
    public String insert(AdderssDTO addressDTO){
        Address address = new Address();
        BeanUtils.copyProperties(addressDTO,address);
        int num = addressMapper.insert(address);
        return num > 0?"插入成功":"插入失败";
    }
    @RequestMapping("/address/select")
    //@ResponseBody
    public List<Address> select(){
        return addressMapper.selectAll();
    }
    @RequestMapping("/address/delete")
    //@ResponseBody
    public String delete(Integer id){
        int num = addressMapper.deleteById(id);
        return num > 0?"删除成功":"删除失败";
    }
    @RequestMapping("/address/update")
    //@ResponseBody
    public String update(Address address){
        int num = addressMapper.updateById(address);
        return num > 0?"修改成功":"修改失败";
    }
}
